Ext.define('DCApp.Cfg',{
	
	singleton   : true,  
    VISITOR: 0.1, 
    APP_NAME:'Extjs & Spring快速原型', 
	ABOUT: '<br><font color="blue">2016年4月</font><br>当前版本<font color="red">0.6</font>',
	AGREEMENT_INFO: '<input type="checkbox" id="cbox2" />本机构保证上述所填信息真实可靠，所提供的证件真实有效，愿意接受平台的背景调查和证件审验，如有虚假信息或虚假证件即视为欺诈行为，按照贵平台相关规定严重违纪处理，同时，本机构承担因资料虚假或隐瞒情况造成的一切后果。',
	ROW_HEIGHT:25,
	
    /*SIM_ENM:{
    	'User':2,
    	'Article':20,
    	'Attach':10,
    	'ETask':100,
    	'LOper':10,
    	'Tag':6
     },*/
 	//for disiable simdata
	SIM_ENM:false,
	usrInfo:null,
    OPTS    : {
    	'doc_linkMan':['欧阳锋','陈刚','杨燕丽','李南书','刘盈','刘茵','林舒'],
    	'doc_type':['故宫讲坛','学术沙龙','快讯','宫廷人物','工程报道','贵宾接待'],
    	'image_imgType':['照片' ,'电子文档','扫描'],
    	'image_imgColor':['彩色' ,'黑白'],
    	'image_imageSource':['影像利用','影像局部','外来影像'],
    	'book_collectiontype':['是','否'],
        'book_commendtype':['是','否']
    } ,
    OPT_STORES:{},
    getWSURL:function (){
    	var wsurl = "ws://"+window.location.host+"/ws/wst.do";
    	return wsurl;
    },    
    constructor : function(options){ 
    	this.ADMINISTRATOR='kkkkkk';
        this.initConfig(options); 
        //Ext.Date.defaultFormat = 'Y-m-d H:i:s';
        Ext.Date.defaultFormat = 'Y-m-d';
        Ext.form.action.Action.submitEmptyText=false;
    },
    getRecentDay:function(day_span, fmt){
    	var today = new Date();
    	var day_before = new Date();
    	day_before.setDate(today.getDate()-day_span);
    	return Ext.util.Format.date(day_before,fmt)
    },
    render_workitem:function (value, metaData) {
    	var map={
        'wgfyr':'翻译人',
        'wwscr':'英文审稿人',
        'djr':'登记人',
        'ysr':'初审',
        'esr':'终审'
    	};
        return map[value];    	
    },

    getListStore:function(model_name,entity_name,pn,sort){
    	var storeId = 'ls_'+entity_name+'.'+pn;
    	var st = Ext.StoreManager.lookup(storeId);
    	if(st)
    		return st;
    	var cfg = {
    		    storeId: storeId,
    		    pageSize: 10,
    		    model: model_name,
    			proxy : {  
        	    	type: 'rest',
        	        url: '/ls/'+entity_name+'/'+pn,
        	    	reader :
        	        {  
        				type : 'json',  
        				rootProperty : 'data',
        				totalProperty:'total'
        	        }
        	    }     		    
    		};
    	if(sort){
    		Ext.applyIf(cfg,{
    			sorters :sort,
               //	remoteFilter: true,
                remoteSort: true
    		});
    	}
    	return  Ext.create('Ext.data.ArrayStore',cfg );
    },
    getDistinctStore:function(entity_name,property_name,filters,func_load){
    	var storeId = 'st_'+entity_name+'.'+property_name;
    	var st = Ext.StoreManager.lookup(storeId);
    	if(!filters)
    		if(st)
    			return st;
    	var config={
    		    storeId: storeId,
    		    pageSize: 100,
    		    fields: ['abbr','name'],

    			proxy : {  
        	    	type: 'rest',
        	        url: '/distinct/'+entity_name+'/'+property_name,
        	    	reader :
        	        {  
        				type : 'json',  
        				rootProperty : 'data',
        				totalProperty:'total'
        	        }
        	    }     		    
    		};
    	if(func_load){
    		config.listeners ={
    			load:func_load
    		};
    	}
    	if(filters){
    		Ext.applyIf(config,{
    		    filters:filters,
               	remoteFilter: true,
                remoteSort: true
    		});
    	}
    	return  Ext.create('Ext.data.ArrayStore', config);
    },
    getStore:function(str){
    	var st = this.OPT_STORES[str];
    	if(st)
    		return st;
    	var data=[];
    	var sa = this.OPTS[str];
    	for(var i=0; i<sa.length; i++){
    		var sv = sa[i];
    		data.push({'abbr':sv,'name':sv});
    	}
    	st =  Ext.create('Ext.data.Store', {
    	    fields: ['abbr', 'name'],
    	    data:data});
    	this.OPT_STORES[str]=st;
    	return st;
    },
    addStore:function(str,val){
    	var st = this.OPT_STORES[str];
    	if(!st)
    		return;
    	var rec=st.findRecord('abbr',val);
    	if(rec)
    		return;
    	this.OPTS[str].push(val);
    	st.add({'abbr':val,'name':val});
    },
    addStores:function(sm){
    	for(var x in sm){
    		this.addStore(x,sm[x]);
    	}
    },
    getUserField:function(filedLabelValue,bindValue){
    	return {
    		flex: 2,
    		fieldLabel: filedLabelValue,
            bind: bindValue,
	        xtype: 'tags',
	        anyMatch:true,
	        store: DCApp.Cfg.getListStore('DCApp.model.User',
	        		'net.bat.entity.User',
	        		'name',[{
	        	 		property: 'dtModify',
	        	 		direction: 'DESC'	        	
	        		}]),
    		listConfig: {
		        getInnerTpl: function() {
		            return '<div>{inf}</div>';
		        }
		    },
	        displayField: 'inf',
	        valueField: 'inf',
	        listeners: {
	        	//选中之后更新UUser dt_modify以便默认排序靠前
	        	select:function( combo, recs, eOpts ){
	        		var rec=recs[0];
	        		rec.set('dtModify',new Date());
	                rec.save({
	                    scope: this,
	                    callback: function(records,operation,succes){
	                    	//console.log('save ok')
	                    }
	                });
	        	}
	        }
    	};
    },
    getAuthorField:function(filedLabelValue,bindValue){
    	return {
    		flex: 2,
    		fieldLabel: filedLabelValue,
            bind: bindValue,
	        xtype: 'tags',
	        anyMatch:true,
	        allowBlank: false,
	        store: DCApp.Cfg.getListStore('DCApp.model.User','net.bat.entity.User','name'),
    		listConfig: {
		        getInnerTpl: function() {
		            return '<div>{inf}</div>';
		        }
		    },
	        displayField: 'inf',
	        valueField: 'inf'
    	};
    },
   getEditorField:function(filedLabelValue,bindValue){
	   return {
    		flex: 2,
    		fieldLabel: filedLabelValue,
            bind: bindValue,
	        xtype: 'displayfield',
	   		renderer:function(val,fld){
	   			var pos=val.lastIndexOf('[');
	   			if(pos!=-1)
	   				return val.substring(0,pos);
	   			else
	   				return val;
	   		}	        
    	};
	  
    },
    parseWord:function(fld,val,opts){
		if(val.indexOf('.doc')==-1 && val.indexOf('.docx')==-1)
			return false;
		Ext.MessageBox.confirm('确认覆盖', '原始文稿上传成功。<br>需要为您提取并填入纯文本和字数吗？',
			function(btn, text){
				if (btn != 'yes')
					return false;
			Ext.Msg.wait('提取', '正在提取纯文本...');
		  Ext.Ajax.request({
            url: '/api/wordtxt',
            method: 'GET',
            reader: 'json',
            headers: { 'Content-Type': 'application/json' },
            params : {'fp':val},
            success: function(response, opts) {
            	var finf = Ext.decode(response.responseText);
        		var vw = this.up('panel');
            	var fld_txt = vw.down('htmleditor');
            	var fld_cout = vw.down('[name=dcTxtwords]');
            	fld_txt.setValue('<pre>'+finf.txt+'</pre>');
            	fld_cout.setValue(finf.count);
            	Ext.Msg.hide();
            },
            failure: function(response, opts) {
            	
            },
            scope:fld
				
			},this);		
        });
    }
}); 
